#!/bin/bash

sudo apt-get update
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
service docker start
systemctl enable docker


#sudo groupadd docker  #默认只有root用户可以用docker，固创建docker用户组加入其它用户
#sudo usermod -aG docker username    #用户添加到docker用户组中（替换username为您的实际用户名）

#增加镜像加速器地址vi /etc/docker/daemon.json 写入下面内容保存，阿里云地址每人都不一样登录阿里云，容器镜像服务查找
cat << "EOF" > /etc/docker/daemon.json
{
"registry-mirrors": ["https://hub-mirror.c.163.com","https://docker.m.daocloud.io","https://ghcr.io","https://mirror.baidubce.com","https://docker.nju.edu.cn","https://do.nark.eu.org","https://docker.1panel.live","https://dockerhub.azk8s.cn","https://ukcz41im.mirror.aliyuncs.com","https://docker.ketches.cn"]
}

EOF

#安装docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose


service docker start
#安装docker portainer 控制面板完成后http://IP:9000

#英文


# docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
#中文


docker run -d --restart=always --name="portainer" -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data mfkd1000/cn_portainer:latest
# 控制面板完成后http://IP:9000

echo "#################################################"

echo "完成后网页登录http://IP:9000  打开docker管理面版"
echo "完成后网页登录http://IP:9000  打开docker管理面版"
echo "完成后网页登录http://IP:9000  打开docker管理面版"

echo "#################################################"

#重启docker

systemctl restart docker 


rm -rf ubuntu_install_docker.sh
# 重启
